package com.bvr;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BidObjectAdapter extends ArrayAdapter<BidObject> {

	private ArrayList<BidObject> items;

	public BidObjectAdapter(Context context, int textViewResourceId,
			ArrayList<BidObject> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);

			v = vi.inflate(R.layout.bid_row, null);
		}
		BidObject o = items.get(position);
		if (o != null) {

			TextView lblBidStatus = (TextView) v.findViewById(R.id.bidStatus);
			TextView lblBidRate = (TextView) v.findViewById(R.id.bidRate);
			TextView lblBidRentalName = (TextView) v.findViewById(R.id.bidRentalName);			
			TextView lblBidDuration = (TextView) v.findViewById(R.id.bidDuration);			
			TextView lblBidHouse = (TextView) v.findViewById(R.id.bidHouse);			
			ImageView imgBid = (ImageView) v.findViewById(R.id.imgBid);

			if (lblBidStatus != null) {
				lblBidStatus.setText(o.getStatus());				
			}
			if (lblBidRentalName != null) {
				lblBidRentalName.setText("Name: " + o.getRentalName());
			}
			if (lblBidDuration != null) {
				lblBidDuration.setText("Duration: " + o.getDurationDetails());
			}
			
			if (lblBidRate != null) {
				lblBidRate.setText("$"+o.getOfferAmount());
			}
			
			if (lblBidHouse != null) {
				String strHouse = o.getBed() + " Bedroom, " + o.getSleep() + " Sleep";
				lblBidHouse.setText("House: " + strHouse);
			}
					

			if (o.getStatus().toString().equalsIgnoreCase("cancelled")) {
				imgBid.setImageResource(R.drawable.pending_icon);
				lblBidStatus.setTextColor(R.color.BidCancelColor);			
			}
			else if (o.getStatus().toString().equalsIgnoreCase("pending")) {
				imgBid.setImageResource(R.drawable.pending_icon);
				lblBidStatus.setTextColor(R.color.BidPendingColor);
				}
			else if (o.getStatus().toString().equalsIgnoreCase("confirmed")) {
				imgBid.setImageResource(R.drawable.accept_icon);
				lblBidStatus.setTextColor(R.color.BidConfirmColor);
				
				}			
			}
		
	
		return v;
	}
}
